package cn.com.gaobb.controller;

import cn.com.gaobb.annotation.LoginToken;
import cn.com.gaobb.dto.ResultDTO;
import cn.com.gaobb.service.UserService;
import cn.com.gaobb.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author gaobb
 */
@RestController
@RequestMapping(value = "/api/user")
public class UserController {
    @Autowired
    private UserService userService;


    @PostMapping(value = "/listOfPage")
    public ResultDTO<ResPageVO<ResUserDetailVO>> listOfPage(@RequestBody ReqPageVO reqVO) {
        return userService.listOfPage(reqVO);
    }

    @LoginToken
    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public ResultDTO<ResLoginVO> login(@RequestParam("name") String name, @RequestParam("password") String password) {
        return userService.login(name, password);
    }

    @RequestMapping(value = "/deduplication", method = RequestMethod.GET)
    public Object deduplication(@PathVariable("name") String name) {
        return userService.Deduplication(name);
    }

    @PostMapping(value = "/add")
    public ResultDTO<ResIdVO> add(@RequestBody ReqUserAddVO vo) {
        return userService.add(vo);
    }

    @PostMapping(value = "/update")
    public ResultDTO update(@RequestBody ReqUserUpdateVO vo) {
        return userService.update(vo);
    }

    @GetMapping(value = "/detail")
    public ResultDTO<ResUserDetailVO> detai(@RequestParam("id")String id) {
        return userService.detail(id);
    }

    @PostMapping(value = "/deleteList")
    public ResultDTO deleteList(@RequestBody ResIdListVO vo) {
        return userService.deleteList(vo);
    }


    /**
     * 注册
     *
     * @param reqVo
     * @return
     */
    @RequestMapping(value = "/register", method = RequestMethod.POST)
    public ResultDTO<ResIdVO> register(@RequestBody ReqRegisterVO reqVo) {
        return userService.register(reqVo);
    }
}
